home *** CD-ROM | disk | FTP | other *** search
/ Aminet 2 / Aminet AMIGA CDROM (1994)(Walnut Creek)[Feb 1994][W.O. 44790-1].iso / Aminet / dev / e / amigae21b.lha / Amiga_E_v2.1b / Sources / Other / CompLine.e < prev    next >
Text File  |  1992-09-02  |  5KB  |  163 lines

  1. /* E language line precompiler for CygnusEd
  2.  
  3.    CompLine takes the current line from CED, and uppercases all E keywords
  4.    in it. It also moves the cursor to the next line. If you don't specify
  5.    the 'noindent' command line option, CompLine adds the same amount
  6.    of spaces or/and tabs to the beginning of the next line, that the previous
  7.    line had.
  8.  
  9.    Installing Compline to CED:
  10.       -Select menu 'Begin short invocation macro'
  11.       -Press RETURN key
  12.       -Select menu 'Send Dos/Arexx command'
  13.       -Type 'compline' or 'compline noindent' to the text requester
  14.       -Choose OK from the requester 'Would you like.. etc'
  15.       -Select menu 'Beg/end definition'
  16.  
  17.    And then save the macros, if you like.
  18.    You also probably want to make compline resident, it's much faster that way.
  19.  
  20.    Author:
  21.       Teemu Suikki
  22.       Internet: tsuikki@lut.fi
  23.       Fidonet:  2:221/103.2
  24. */
  25.  
  26. OPT OSVERSION=37
  27.  
  28. MODULE 'rexx/storage','rexxsyslib','exec/nodes'
  29.  
  30. DEF myport,line[500]:STRING,pos
  31.  
  32. PROC main()
  33.    DEF indent=TRUE
  34.  
  35.    IF InStr(arg,'noindent',0)<>-1 THEN indent:=FALSE
  36.  
  37.    StrCopy(line,'text ',ALL)
  38.  
  39.    IF (rexxsysbase:=OpenLibrary('rexxsyslib.library',0))=0 THEN clean('No ARexx installed!')
  40.  
  41.    IF (myport:=CreateMsgPort())=0 THEN clean('No memory for a message port!')
  42.  
  43.    IF send('status 55',line) THEN clean('Couldn\at get line from CED!')
  44.  
  45.    pos:=TrimStr(line+4)           /* count those tabs and spaces           */
  46.    IF pos[]                      /* and add them to the end of the string.*/
  47.       IF indent THEN StrAdd(line,line+5,pos-line-5)
  48.  
  49.       check()
  50.  
  51.       send('Beg of line',NIL)    /* Send the line back to CED */
  52.       send('Delete to EOL',NIL)
  53.       send(line,NIL)
  54.    ELSE
  55.       send('text \n',NIL)
  56.    ENDIF
  57.  
  58.    clean(0)
  59. ENDPROC
  60.  
  61. /* This procedure uppercases those keywords */
  62. PROC check()
  63.    DEF upper[100]:STRING,quote=0,len,x,a
  64.  
  65.    WHILE Char(pos)
  66.       IF quote                               /* Skip quotes, " or ' */
  67.          a:=InStr(pos,[quote*256]:INT,0)
  68.          quote:=0
  69.          IF a=-1 THEN RETURN
  70.          pos:=pos+a+1
  71.       ENDIF
  72.  
  73.       x:={separators}
  74.       len:=1000000
  75.  
  76.       WHILE Char(x)                          /* Find the next word */
  77.          a:=InStr(pos,x,0)
  78.          IF (a>=0) AND (a<len) THEN len:=a
  79.          x:=x+2
  80.       ENDWHILE
  81.  
  82.       a:=Char(pos+len)
  83.  
  84.       IF (a="'") OR (a=34) THEN quote:=a
  85.  
  86.       StrCopy(upper,pos,len)
  87.       UpperStr(upper)
  88.  
  89.       x:={keywords}
  90.  
  91.       WHILE Char(x) AND (StrCmp(upper,x,ALL)=0) DO x:=x+10
  92.  
  93.       IF Char(x)                             /* Copy uppercased string back */
  94.          FOR x:=0 TO len-1 DO PutChar(pos+x,Char(upper+x))
  95.       ENDIF
  96.  
  97.       pos:=pos+len+1
  98.    ENDWHILE
  99. ENDPROC
  100.  
  101. PROC clean(error)
  102.    IF myport THEN DeleteMsgPort(myport)
  103.    IF rexxsysbase THEN CloseLibrary(rexxsysbase)
  104.  
  105.    IF error
  106.       EasyRequestArgs(NIL,[20,0,'E line precompiler',error,'OK'],NIL,NIL)
  107.       CleanUp(10)
  108.    ENDIF
  109.    CleanUp(0)
  110. ENDPROC
  111.  
  112. /* Send an arexx command to CED.
  113.  str=string (command) to send
  114.  result=string where the result string is _appended_, or NIL.  */
  115. PROC send(str,result)
  116.    DEF rexxport,msg:PTR TO rexxmsg,argstr,r=FALSE,len
  117.  
  118.    IF msg:=CreateRexxMsg(myport,NIL,NIL)
  119.       msg.action:=RXCOMM OR RXFF_STRING OR IF result THEN RXFF_RESULT ELSE 0
  120.  
  121.       IF argstr:=CreateArgstring(str,StrLen(str))
  122.          PutLong(msg.args,argstr)
  123.          Forbid()
  124.          IF rexxport:=FindPort('rexx_ced')
  125.             PutMsg(rexxport,msg)
  126.             Permit()
  127.  
  128.             WaitPort(myport)
  129.             GetMsg(myport)
  130.             r:=msg.result1
  131.             IF msg.result2
  132.                len:=InStr(msg.result2,'\n',0)+1
  133.                StrAdd(result,msg.result2,len)
  134.                FreeMem(msg.result2,len)
  135.             ENDIF
  136.          ELSE
  137.             Permit()
  138.             r:=TRUE
  139.          ENDIF
  140.          DeleteArgstring(argstr)
  141.       ENDIF
  142.       DeleteRexxMsg(msg)
  143.    ENDIF
  144. ENDPROC r
  145.  
  146. keywords:
  147. CHAR  'PROC\0.....','ENDPROC\0..','IF\0.......','ENDIF\0....','VOID\0.....',
  148.       'WHILE\0....','ENDWHILE\0.','FOR\0......','ENDFOR\0...','SELECT\0...',
  149.       'CASE\0.....','DEFAULT\0..','ENDSELECT\0','REPEAT\0...','UNTIL\0....',
  150.       'JUMP\0.....','DEF\0......','ELSE\0.....','INCBIN\0...','LONG\0.....',
  151.       'INT\0......','CHAR\0.....','INC\0......','DEC\0......','THEN\0.....',
  152.       'LOOP\0.....','ENDLOOP\0..','DO\0.......','AND\0......','OR\0.......',
  153.       'CONST\0....','OPT\0......','MODULE\0...','STACK\0....','FULL\0.....',
  154.       'LARGE\0....','ASM\0......','NOWARN\0...','TO\0.......','STEP\0.....',
  155.       'ARRAY\0....','STRING\0...','DIR\0......','PTR\0......','OF\0.......',
  156.       'ELSEIF\0...','LIST\0.....','OBJECT\0...','ENDOBJECT\0','SIZEOF\0...',
  157.       'RETURN\0...','OSVERSION\0','ENUM\0.....','SET\0......','BUT\0......',
  158.       'HANDLE\0...','EXCEPT\0...','RAISE\0....',0
  159.  
  160. separators:
  161. CHAR  ',\0','.\0',':\0',';\0',' \0','=\0','\n\0','`\0','\t\0','\a\0','"\0',0
  162.  
  163.